package com.boco.blch.analysiser.compliance.HW.manager;

import java.util.regex.Pattern;

import com.boco.blch.analysiser.compliance.ComplianceResolved;
import com.boco.blch.analysiser.util.PortRangeUtil;

public class BOCO_Flume_VisitCtl_ServiceStartMin implements ComplianceResolved{

	@Override
	public int realEchoResolved(String echoResult) {
		int result = UNKNOWN; 
		if(echoResult.contains(NoPermission1)||echoResult.contains(NoPermission2)||echoResult.contains(NoPermission3)){
			return FAILED;
		}
		else if(echoResult != null && echoResult.trim().length() > 0){
			String[] str1 = echoResult.split("\n");//根据\n拆分为数组
			if(str1!=null && str1.length>0){
				for (int i = 0; i < str1.length; i++) {
					String []str2 = str1[i].split(":");//根据：拆分为数组
					for (int j = 0; j < str2.length; j++) {
						String port = str2[j].trim();
						if(port.indexOf("  ") != -1){
							port = port.substring(0, port.indexOf("  "));
						}
						//判断数字 正则
						Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");  //[0-9]*
						if(port != null && port.length()>0){
							boolean flag = pattern.matcher(port).matches();
							if(flag){
								//判断待测端口号是否在端口矩阵中
								boolean resultFlag = PortRangeUtil.inRange("flume", Integer.parseInt(port));
								if(!resultFlag){//待测端口不在端口矩阵中
									result = FAILED;
									break;
								}else{
									result = SUCCESS;
								}
							}
						}
					}
					if(result == FAILED){
						break;
					}
				}
			}
		}
		return result;

	}

}
